package org.neuedu.fly.web;

import org.neuedu.fly.entity.User;
import org.neuedu.fly.entity.vo.ResponseEntity;
import org.neuedu.fly.service.PostService;
import org.neuedu.fly.util.SysUtil;

import javax.servlet.annotation.WebServlet;

@WebServlet("/index/*")
public class postIndexServlet extends BaseServlet {
    private PostService postService = new PostService();

    public ResponseEntity indexPage() {
        String pageIndex = request.getParameter("page");
        String pageSize = request.getParameter("limit");
        String isClosed = request.getParameter("isClosed");
        String isFine = request.getParameter("isFine");
        String columnName = request.getParameter("columnName");
        return postService.indexPage(pageIndex, pageSize, isClosed, isFine,columnName);
    }

    public ResponseEntity editPost(){
        String postId = request.getParameter("postId");
        String isStatus = request.getParameter("status");
        String isTop = request.getParameter("isTop");
        String isFine = request.getParameter("isFine");
        return postService.editPost(postId,isStatus,isTop,isFine);
    }

    public ResponseEntity topPage(){
        return postService.isTopPage(1);
    }

    public ResponseEntity hotPost(){
        return postService.hotPost();
    }

    public ResponseEntity sendPost(){
        String userId = request.getParameter("userId");
        String columnId = request.getParameter("column");
        String title = request.getParameter("title");
        String context = request.getParameter("context");
        String kiss = request.getParameter("kiss");
        return postService.sendPost(userId,columnId,title,context,kiss);
    }

    //id查询帖子
    public ResponseEntity findPost(){
        String postId = request.getParameter("postId");
        return postService.findReplyByPostId(postId);
    }

    //查询用户id帖子
    public ResponseEntity findPostByUserId() {
        User user = (User) request.getSession().getAttribute(SysUtil.CURRENT_USER);
        Integer userId = user.getId();
        Integer pageIndex = Integer.parseInt(request.getParameter("page"));
        Integer pageSize = Integer.parseInt(request.getParameter("limit"));
        return postService.findPostByUserId(userId, pageIndex, pageSize);
    }

}
